package com.sky.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sky.Service.OrderService;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理")
@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("分页查询订单")
    @GetMapping("/conditionSearch")
    public Result<IPage<Orders>> getByPage(OrdersPageQueryDTO ordersPageQueryDTO) {
        System.out.println("ordersPageQueryDTO:" + ordersPageQueryDTO);
        IPage<Orders> queryByPage = orderService.getQueryByPage(ordersPageQueryDTO);
        return Result.success(queryByPage);
    }

    @ApiOperation("获取订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderDetail(@PathVariable Long id){
        System.out.println("id:" + id);
        OrderVO adminOrderDetail = orderService.getAdminOrderDetail(id);
        return Result.success(adminOrderDetail);
    }

    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result<String> confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        System.out.println("ordersConfirmDTO:" + ordersConfirmDTO);
        orderService.confirmOrder(ordersConfirmDTO);
        return Result.success("接单成功！");

    }

    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result<String> rejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        System.out.println("ordersRejectionDTO:" + ordersRejectionDTO);
        orderService.rejectOrder(ordersRejectionDTO);
        return Result.success("拒单成功！");
    }

    @ApiOperation("订单发货")
    @PutMapping("/delivery/{id}")
    public Result<String> deliveryOrder(@PathVariable Long id){
        System.out.println("id:" + id);
        orderService.deliveryOrder(id);
        return Result.success("订单派送成功!");
    }

    @ApiOperation("订单完成")
    @PutMapping("/complete/{id}")
    public Result<String> completeOrder(@PathVariable Long id){
        System.out.println("id:" + id);
        orderService.completeOrder(id);
        return Result.success("订单完成!");
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result<String> cancelOrder(OrdersCancelDTO ordersCancelDTO){
        System.out.println("ordersCancelDTO:" + ordersCancelDTO);
        orderService.cancelAdminOrder(ordersCancelDTO);
        return Result.success("订单取消成功！");
    }

    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<String> getOrderCounts(){
        return null;
    }

}
